package com.liy.cloud.common.feign.fallback;

import com.liy.cloud.common.feign.api.SysFeignClient;
import com.das.framework.common.extvo.ResultVO;
import com.das.framework.common.vo.PageVO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 熔断处理:
 * 该处理方式可 查看到失败的异常信息，推荐使用该工厂方式
 */
@Component
public class SysFeignClientFallbackFactory implements FallbackFactory<SysFeignClient> {

    private static final Logger log = LoggerFactory.getLogger(SysFeignClientFallbackFactory.class);

    @Override
    public SysFeignClient create(Throwable e) {

        log.info("sys feign fallback; reason was: {}", e.getMessage());

        return new SysFeignClient() {


            @Override
            public PageVO getDictItemEnableList(Object vo, Integer pageSize, Integer pageNo) {

                PageVO pageVO = new PageVO();
                pageVO.setStatus("500");
                pageVO.setMessage("根据条件查询有效字典列表数据异常: " + e.getMessage());
                return pageVO;
            }

            @Override
            public PageVO getDictItemSelectTypecode(Object vo, Integer pageSize, Integer pageNo) {
                PageVO pageVO = new PageVO();
                pageVO.setStatus("500");
                pageVO.setMessage("根据条件查询字典列表数据异常: " + e.getMessage());
                return pageVO;
            }

            @Override
            public PageVO queryDictItem(Object vo, Integer pageSize, Integer pageNo) {
                PageVO pageVO = new PageVO();
                pageVO.setStatus("500");
                pageVO.setMessage("根据条件查询字典列表数据异常: " + e.getMessage());
                return pageVO;
            }

            @Override
            public ResultVO findAccountBy(String account) {
                return new ResultVO(false, "查询用户信息异常: " + e.getMessage(), "500");
            }

            @Override
            public PageVO getAccountPage(Object vo, Integer pageSize, Integer pageNo) {
                PageVO pageVO = new PageVO();
                pageVO.setStatus("500");
                pageVO.setMessage("分页查询用户信息数据异常: " + e.getMessage());
                return pageVO;
            }
        };
    }

}
